﻿@using Modules.Template.Shared.CodeTemplate
@inherits BasePage
<GridRow Align="middle" Style="height:48px;">
    <GridCol Span="12">
        @if (TableOptions.IsEdit)
        {
            <Button OnClick="@AddClick" Icon="@IconType.Outline.Plus" Type="primary">添加</Button>
        }
    </GridCol>

    <GridCol Span="12">
        <div class="Table_Right_Tool">
            <Button Size="@ButtonSize.Small" Type="@ButtonType.Text" Icon="@IconType.Outline.Reload" OnClick="ResetTable">刷新</Button>
            @if (TableOptions.IsEdit)
            {
                <Button Type="@ButtonType.Text" Size="@ButtonSize.Small" Icon="@IconType.Outline.Delete" OnClick="@BatchDelClick">批量</Button>
                <Button Size="@ButtonSize.Small" Type="@ButtonType.Text" Icon="@IconType.Outline.Edit">批量</Button>
            }
        </div>
    </GridCol>
</GridRow>

<Table @ref="AntTable" Resizable
       RowClassName="@(x => x.Data.Row_CSS_Class)"
       ScrollY="@TableOptions.ScrollY"
       Bordered="true"
       Size=@TableSize.Small
       TItem="CodeTemplateVM"
       DataSource="TableModel.DataSource"
       @bind-PageIndex="TableModel.PageIndex"
       @bind-PageSize="TableModel.PageSize"
       @bind-SelectedRows="TableModel.SelectedRows"
       Total="TableModel.TotalCount"
       Loading="TableModel.Loading"
       OnChange="HandleTableChangeAsync"
       RemoteDataSource>
    <ChildContent>
        <Selection Type="checkbox" />
        @if (TableOptions.IsEdit)
        {
            <ActionColumn Title="操作" Width="70">
                <Space Size="@($"1")">
                    <SpaceItem>
                        <Button Size="@ButtonSize.Small" OnClick="()=>EditClick(context)" Type="@ButtonType.Link" Icon="@IconType.Outline.Edit" />
                    </SpaceItem>
                    @if (TableOptions.IsDelete)
                    {
                        <SpaceItem>
                            <Button Size="@ButtonSize.Small" OnClick="()=>DelClick(context)" Type="@ButtonType.Link" Icon="@IconType.Outline.Delete" />
                        </SpaceItem>
                    }
                </Space>
            </ActionColumn>
        }

        @*
        代码生成器会覆盖标记之间的内容。*@
        @*CodeGenerator start*@
        <AntDesign.PropertyColumn Property="c=>c.Id" Width="150" Sortable Filterable></AntDesign.PropertyColumn>
        <AntDesign.PropertyColumn Property="c=>c.Username" Width="150" Sortable Filterable></AntDesign.PropertyColumn>
        @*CodeGenerator end*@
    </ChildContent>
    <PaginationTemplate>
        <Pagination Style="text-align:center;line-height:38px;"
                    Total="context.Total"
                    Size="PaginationSize.Small"
                    ShowTotal=showTotal
                    PageSize="context.PageSize"
                    Current="context.PageIndex"
                    OnChange="context.HandlePageChange"
                    PageSizeOptions="TableOptions.PageSizeOptions" />
    </PaginationTemplate>
</Table>

<Modal Title="@Dialog.Title"
       @bind-Visible="@Dialog.Visible"
       Width="@Dialog.Width"
       Draggable="@Dialog.Draggable"
       Footer="null">
    <CodeTemplateAdd model="@EditRow" IsAdd="@IsAdd" OnValueCallback="OnValueCallback"></CodeTemplateAdd>
</Modal>

@code
{
    Func<PaginationTotalContext, string> showTotal = ctx => $"总计 {ctx.Total} 项";
}